package com.shuai.model.converter;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.shuai.model.po.SysPermission;
import com.shuai.model.vo.SysPermissionVo;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 权限信息转换器
 *
 * @author shuai
 * @since 2022
 */
@Slf4j
public class SysPermissionConverter {
    /**
     * Po转换Vo
     * @param source
     * @return
     */
    public static SysPermissionVo convertToVoByPo(SysPermission source) {
        SysPermissionVo target = new SysPermissionVo();
        BeanUtil.copyProperties(source, target);
        return target;
    }

    /**
     * Po转换Vo
     * @param sources
     * @return
     */
    public static List<SysPermissionVo> convertToVoByPo(List<SysPermission> sources) {
        List<SysPermissionVo> newList = CollUtil.newArrayList();
        sources.stream().forEach(item->{
            SysPermissionVo target = new SysPermissionVo();
            BeanUtil.copyProperties(item, target);
            newList.add(target);
        });
        return newList;
    }

}
